//
//  SISSUploadImageCollectionViewCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/2.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSUploadImageCollectionViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSUploadImageCollectionViewCell ()

/// imageView
@property (weak, nonatomic) UIImageView *imageView;
/// deleteButton
@property (weak, nonatomic) UIButton *deleteButton;

@end
@implementation SISSUploadImageCollectionViewCell

- (void)setImageUrl:(NSString *)imageUrl {
    _imageUrl = imageUrl;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"图片加载占位符"]];
}

- (void)setImage:(UIImage *)image {
    _image = image;
    self.imageView.image = image;
}

- (void)setIsShowDeleteButton:(BOOL)isShowDeleteButton {
    _isShowDeleteButton = isShowDeleteButton;
    
    self.deleteButton.hidden = !isShowDeleteButton;
}

- (void)deleteButtonClickAction {
    
    if ([self.delegate respondsToSelector:@selector(deleteButtonClickAcionWithCell:)]) {
        [self.delegate deleteButtonClickAcionWithCell:self];
    }
}

- (void)initUI {
    [super initUI];
    
//    if (self.imageSize.width == 0) {
//        self.imageSize = CGSizeMake(SCREEN_WIDTH/3 - 10, 90);
//    }
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.userInteractionEnabled = YES;
    [self.contentView addSubview:imageView];
    self.imageView = imageView;
    
    UIButton *deleteButton = [[UIButton alloc] init];
    [deleteButton setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(deleteButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:deleteButton];
    self.deleteButton = deleteButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.mas_equalTo(weakSelf.contentView).offset(8);
//        make.size.mas_equalTo(weakSelf.imageSize);
        make.edges.equalTo(weakSelf.contentView);
    }];
    
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(weakSelf.contentView);
        
    }];
}

@end
